<template>
	<view>
		<u-navbar :fixed="true" :placeholder="true" :title="pointName" @leftClick="leftClick" bgColor="#0F53AC"
			leftIconColor="#fff">
		</u-navbar>
		<view class="weibao-item">
			<view class="item-top">
				<view class="left">
					<view>{{content}}</view>
				</view>
			</view>
		</view>
		<view class="htLists-box">

			<view class="htLists-tips">
				<!-- <u-notice-bar text="提示：点击隐患列表可查看隐患，再次点击取消查看"></u-notice-bar> -->
				提示：点击隐患列表可查看隐患，再次点击取消查看
			</view>
			<view class="htLists-detail" v-for="(item,index) in htLists" :key="index"
				@click="handleHtDetail(item,index)">
				<view class="htlist-detail-box">
					<view class="htlist-detail-left">
						<view class="htLists-title">{{item.title}}</view>
						<text class="htLists-name">{{item.dangerDesc.split('&')[0]}}</text> <!-- 列表内容 -->
					</view>
					<view :class="index===htIndex&&infoShow?'lox-box-true':'look-box'">
						<image v-if="index===htIndex&&infoShow" src="@/static/images/index/look-true.png"></image>
						<image v-else src="@/static/images/index/look-false.png"></image>
						<view class="look">
							查看
						</view>
					</view>
				</view>

			</view>
		</view>
		<template v-if='infoShow'>
			<view class="kiss-upDown-list" v-if="isInspec==0">
				<view class="bx-list-title">
					<view class="left">
						<view style="color: red;" v-if="isInspec == 0">*</view>
						隐患等级
					</view>
				</view>
				<view class="bx-list-title" style="margin-top: 24rpx;">
					<u-radio-group v-model="dataForm.dangerLevel" placement="row">
						<u-radio :label="'一般隐患'" :name="1" activeColor="#0F53AC"
							:labelColor="dataForm.dangerLevel==1 ? '#0F53AC':''">
						</u-radio>
						<u-radio :customStyle="{marginLeft: '100rpx'}" :label="'重大隐患'" :name="2" activeColor="#0F53AC"
							:labelColor="dataForm.dangerLevel==2 ? '#0F53AC':''">
						</u-radio>
					</u-radio-group>
				</view>
			</view>
			<view class="kiss-list" v-else>
				<view class="kiss-list-title">
					<view class="left">
						隐患等级
					</view>
					<view class="right1">
						<view :class="[dataForm.dangerLevel == 1?'level-small':'level-big']">
							{{ dataForm.dangerLevel == 1?'一般隐患':'重大隐患' }}
						</view>
					</view>
				</view>
			</view>
			<view class="kiss-list">
				<view class="kiss-list-title2" :style="{padding: isInspec == 0?'24rpx 32rpx':'32rpx 32rpx 0'}">
					<view class="left">
						<view style="color: red;" v-if="isInspec == 0">*</view>
						隐患位置
					</view>
					<view class="right1" v-if="isInspec == 0" @click="handleUnit()">
						<view class="iconfont icon-app-add sm-sd">请选择</view>
					</view>
				</view>
				<view class="kiss-list-input" style="border-bottom: none;padding-bottom: 0;" v-if="isInspec == 0">
					<view class="my-input">
						<u-input border="surround" cursorSpacing="60" placeholder="请输入隐患位置" v-model="dataForm.dangerSite" inputAlign="left"
							maxlength="32">
							<template slot="suffix">
								<div class="myLength">{{dangerSiteLength}}/32</div>
							</template>
						</u-input>
					</view>
				</view>
				<view class="textInput" style="padding: 16rpx 32rpx 0;" v-else>{{dataForm.dangerSite || '无'}}
				</view>
			</view>
			<view class="kiss-title" :style="infoShow?'margin-top:32rpx;border-top:2rpx solid #f5f5f5;':''">
				<view class="left">
					<view style="color: red;" v-if="isInspec == 0">*</view>
					隐患照片<view v-if="isInspec == 0" style="color: #8c8c8c;">(可传3张)</view>
				</view>
			</view>
			<view class="kiss-upload" style="padding: 0 32rpx 32rpx 32rpx;">
				<view class="textInput" v-if="isInspec == 1 && fileList1.length == 0">暂无记录照片</view>
				<view class="imgBox" v-else-if="isInspec == 1 && fileList1.length > 0">
					<view class="img" v-for="v in imgList">
						<image @tap="previewImage(v,imgList)" :src="v"></image>
					</view>
					<video class="video" v-for="v in videoList" :src="v"></video>
				</view>
				<uploadVideo v-else :fileMaxNum="3" @getdata="getdata" :fileType="24" @delete="deletePicture"
					:file="file">
				</uploadVideo>

			</view>
			<view class="kiss-upDown-list">
				<view class="bx-list-title">
					<view class="left">
						<view style="color: red;" v-if="isInspec == 0">*</view>
						隐患描述
					</view>
				</view>
				<view class="input-textrea" v-if="isInspec == 0">
					<u--textarea class="textrea" cursorSpacing="60" count v-model="dataForm.dangerDesc" placeholder="请输入隐患描述"
						maxlength="360">
					</u--textarea>
				</view>
				<view class="textInput" v-else>{{dataForm.dangerDesc || '无'}}</view>
			</view>
			<view class="kiss-list">
				<view class="kiss-list-title" @click="showReason = true">
					<view class="left">
						隐患形成原因
					</view>
					<view class="right1" v-if="isInspec == 0">
						<view :class="[dataForm.dangerReason != '' ? 'select-bg' : 'sel']">
							{{ dataForm.dangerReason != '' ? dangerReasonData[dataForm.dangerReason - 1] : '请选择' }}
						</view>
						<u-icon name="arrow-right"></u-icon>
					</view>
					<view class="right1" v-else>
						<view :class="[dataForm.dangerReason != '' ? 'select-bg' : '']">
							{{ dataForm.dangerReason != '' ? dangerReasonData[dataForm.dangerReason - 1] : '无' }}
						</view>
					</view>
				</view>
			</view>

			<view class="kiss-upDown-list">
				<view class="bx-list-title">
					<view class="left">
						整改意见
					</view>
				</view>
				<view class="input-textrea" v-if="isInspec == 0">
					<u--textarea class="textrea" :cursorSpacing="60" count v-model="dataForm.suggestion" placeholder="请输入整改意见"
						maxlength="360">
					</u--textarea>
				</view>
				<view class="textInput" v-else>{{dataForm.suggestion || '无'}}</view>
			</view>
			<view class="kiss-upDown-list" v-if="!isRiks">
				<view class="bx-list-title">
					<view class="left">
						法律法规
					</view>
				</view>
				<view class="textInput">{{rule}}</view>
			</view>
			<view class="kiss-list">
				<view class="kiss-list-title" @click="handleUser">
					<view class="left">
						<view style="color: red;" v-if="isInspec == 0">*</view>
						整改人
					</view>
					<view class="right1" v-if="isInspec == 0">
						<view :class="[dataForm.realRectify != '' ? 'select-bg' : 'sel']">
							{{ dataForm.realRectify != '' ? dataForm.realRectify : '请选择' }}
						</view>
						<u-icon name="arrow-right" style="color: #8C8C8C;"></u-icon>
					</view>
					<view class="right1" v-else>
						<view :class="[dataForm.realRectify != '' ? 'select-bg' : '']">
							{{ dataForm.realRectify != '' ? dataForm.realRectify : '无' }}
						</view>
					</view>
				</view>
				<view class="kiss-list-title" @click="handleTime">
					<view class="left">
						<view style="color: red;" v-if="isInspec == 0">*</view>
						整改时限
					</view>
					<view class="right1" v-if="isInspec == 0">
						<view :class="[dataForm.limitDate != '' ? 'select-bg' : 'sel']">
							{{ dataForm.limitDate  ? dataForm.limitDate : '请选择' }}
						</view>
						<u-icon name="arrow-right" style="color: #8C8C8C;"></u-icon>
					</view>
					<view class="right1" v-else>
						<view :class="[dataForm.limitDate != '' ? 'select-bg' : '']">
							{{ dataForm.limitDate  ? dataForm.limitDate : '无' }}
						</view>
					</view>
				</view>

				<!-- <view class="kiss-list-title">
					<view class="left">
						隐患公示
					</view>
					<view class="right1">
						<u-switch :disabled="isInspec!=0" v-model="dataForm.publicityFlag" @change="onChangeGongshi">
						</u-switch>
					</view>
				</view>
				<view class="kiss-list-title" v-if="dataForm.publicityFlag" @click="handlePublicity">
					<view class="left">
						<view style="color: red;">*</view>
						公示部门
					</view>
					<view class="right1" v-if="isInspec == 0">
						<view :class="[dataForm.publicityDeptNames != '' ? 'select-bg' : 'sel']">
							{{ dataForm.publicityDeptNames != '' ? dataForm.publicityDeptNames : '请选择' }}
						</view>
						<u-icon name="arrow-right"></u-icon>
					</view>
					<view class="right1" v-else>
						<view :class="[dataForm.publicityDeptNames != '' ? 'select-bg' : '']">
							{{ dataForm.publicityDeptNames != '' ? dataForm.publicityDeptNames : '无' }}
						</view>
					</view>

				</view> -->
				<!-- <view class="kiss-list-title" v-if="dataForm.publicityFlag">
					<view class="left">
						发送短信通知
					</view>
					<view class="right1">
						<u-switch :disabled="isInspec!=0" v-model="dataForm.sendSmsFlag" @change="onChangesendSmsFlag">
						</u-switch>
					</view>
				</view> -->
			</view>
		</template>

		<template v-if="isLook == 0">
			<view class="xing-subside"></view>
			<view class="xing-bottom-double">
				<view class="btn-left" @click="handleBack">返回</view>
				<view class="btn-right" @click="saveConfirm">{{btnType==='save'?'保存隐患信息':'添加隐患信息'}}</view>
			</view>
		</template>


		<u-datetime-picker :disabled="isInspec != 0" :show="showTime" :minDate="value4" :value="value4" mode="date"
			@cancel="cancelTime" @confirm="confirmTime">
		</u-datetime-picker>

		<!-- 隐患形成原因 -->
		<u-picker :show="showReason" :columns="reasonColumns" keyName="name" @confirm="onChangeReason"
			@cancel="cancelReason">
		</u-picker>

		<tki-tree ref="tkitree" :range="treeList" rangeKey="configValue" idKey="id" :selectParent="true"
			confirmColor="#0f53ac" @confirm="confirmTree" />

		<u-overlay :show="tipShow" mode="center" round="6">
			<view class="tip_box">
				<view class="title1">
					提示
				</view>
				<view class="top">
					<text>当前未配置区域，请手动输入</text>
				</view>
				<view class="btn">
					<view class="cacel_btn" @click="tipShow = false">
						知道了
					</view>
				</view>
			</view>
		</u-overlay>
	</view>
</template>

<script>
	import uploadVideo from '@/components/uploadVideo/index.vue';
	import tkiTree from "../components/tki-tree/tki-tree.vue"
	export default {
		components: {
			uploadVideo,
			tkiTree
		},
		data() {
			return {
				tipShow: false,
				treeList: [],
				file: '',
				videoList: [],
				imgList: [],
				showTime: false,
				value4: Number(new Date()),
				indicatorStyle: `height: ${Math.round(uni.getSystemInfoSync().screenWidth/(750/100))}px;`,
				valueArr: [0, 0], // 用于判断当前滑动的是哪一列
				//法律法规
				rule: '',
				//隐患列表
				htLists: [],
				//控制信息填写
				infoShow: false,
				//判断按钮这里是（添加add，或者保存save）
				btnType: 'add',
				//这里需要展缓一下当前点击的数据做判断用
				htInfo: {},
				//判断点击的是谁
				htIndex: '',
				// 检查内容id
				ruleId: '',
				infoList: {},
				saveParams: {
					pictures: '',
				},
				pictrueList: [],
				type: '', //1-维保任务 2-点检任务
				fileList1: [],
				content: '',
				// 当前隐患相关信息
				dataForm: {
					dangerLevel: '', //隐患等级 1.一般隐患；2.重大隐患；
					dangerPhoto: '', //照片
					dangerSite: '', //隐患位置
					dangerDesc: '', //隐患描述
					suggestion: '', //整改意见
					dangerReason: '', //隐患形成原因
					rectifyDeptId: '',
					rectifyDeptName: '', //整改部门
					rectifyUid: "",
					rectifyName: "", //整改人姓名
					realRectify: '',
					limitDate: '', //整改时限
					remark: '',
					deptIds: '', //公示部门
					publicityFlag: false, // 隐患是否公示；0.否；1.是;
					publicityDeptIds: '', //公式部门id
					publicityDeptNames: '', //公式部门名称
					sendSmsFlag: false //是否发送短信；0.否；1.是；
				},
				isInspec: 0,
				sourceType: ['album', 'camera'],
				userColumns: [],
				isShow: true,
				isRiks: false,
				pointName: '隐患列表',
				unitName: '',
				showReason: false,
				dangerReasonData: ['人的不安全行为', '物的不安全状态', '管理缺陷', '环境与场所', '其他'],
				reasonColumns: [
					[{
							id: 1,
							name: '人的不安全行为'
						},
						{
							id: 2,
							name: '物的不安全状态'
						},
						{
							id: 3,
							name: '管理缺陷'
						},
						{
							id: 4,
							name: '环境与场所'
						},
						{
							id: 5,
							name: '其他'
						},
					]
				],
				isLook: 1,
				regionName: '',
				suggestion: '',
				type: 0,
				planName: '',
				dangerSiteLength: 0
			}
		},
		watch: {
			'dataForm.dangerSite'(val) {
				this.dangerSiteLength = val.length
			},
		},
		onLoad(options) {
			this.htLists = [{
				id: 1,
				title: '隐患1',
				dangerDesc: '隐患显示内容'
			}]
			this.infoShow = false

			if (options) {
				// 检查内容id
				this.ruleId = options.ruleId
				// 巡查任务id
				this.inspectionId = options.inspectionId
				this.rule = options.rule || '无'
				this.content = options.content
				this.isShow = options.isShow
				if(options.isRiks){
					this.isRiks = JSON.parse(options.isRiks)
				}
				this.isLook = options.isLook
				this.regionName = options.regionName
				this.suggestion = options.suggestion || ''
				this.type = options.type
				this.planName = options.planName
				if (this.isRiks) {
					this.pointName = options.pointName
					this.unitName = options.unitName
					this.dataForm.dangerSite = options.unitName
				}else{
					this.dataForm.dangerSite = options.regionName //默认隐患位置
					this.dataForm.suggestion = options.suggestion //默认整改意见
				}
				//这里获取隐患列表并渲染
				this.getHtList()
			}
			this.getRegionData('')

			// 公式部门选择回调
			uni.$on('setBumenList', (data) => {
				let idArr = []
				let nameArr = []
				data.forEach(item => {
					idArr.push(item.id)
					nameArr.push(item.deptName)
				})
				this.dataForm.publicityDeptIds = idArr.join(',')
				this.dataForm.publicityDeptNames = nameArr.join(',')
			})

			// 整改人员选择回调
			uni.$on('setUser', (data) => {
				this.dataForm.rectifyDeptId = data.parentId
				this.dataForm.rectifyDeptName = data.deptName
				this.dataForm.rectifyUid = data.id
				this.dataForm.rectifyName = data.name
				this.dataForm.realRectify = data.deptName + '-' + data.name
			})
			
			// 单元选择回调
			uni.$on('setUnit', (data) => {
				this.dataForm.dangerSite = data.configValue
			})
		},
		onUnload() {
			var pages = getCurrentPages(); //当前页面栈
			if (pages.length > 1) {
				var beforePage = pages[pages.length - 2]; //获取上一个页面实例对象
				beforePage.data.needGetData = true;
			}
		},
		onShow() {
			
		},
		methods: {
			getRegionData(k) {
				let params = {
					configType: 'risk_unit',
					keyword: k
				}
				uni.$u.http.post(`/check/pc/riskPoint/getRiskUnit`, params).then(res => {
					if (res.code == 0) {
						this.treeList = res.data
						console.log(this.treeList);
					}
				})
			},
			confirmTree(e) {
				console.log(e);
				if (e[0]) {
					this.dataForm.dangerSite = e[0].configValue
				}
			},
			//选择隐患位置
			handleUnit() {
				if (this.treeList.length != 0) {
					uni.navigateTo({
						url: `/pages/subPackagesA/riskIdtion/unitTree`
					})
				} else {
					this.tipShow = true
				}
				
			},
			leftClick() {
				this.handleBack()
			},
			getHtList() {
				uni.$u.http.get(`/check/mobile/appDangerInfo/getDangerList/${this.ruleId}/${this.inspectionId}`)
					.then(res => {
						if (res.code == 0) {
							if (res.data.length <= 0) {
								this.htLists = []
								this.infoShow = true
								this.dataForm = {}
							} else {
								let arr = []
								res.data.forEach((item, index) => {
									let obj = {
										id: item.id,
										title: '隐患' + (index + 1),
										dangerDesc: item.dangerDesc
									}
									arr.push(obj)
								})

								this.infoShow = false
								this.htLists = arr
							}
						}
					})
			},
			getdata(e) {
				this.pictrueList = e;
				this.fileList1 = [];
				if (this.pictrueList.length > 0) {
					this.saveParams.pictures = "";
					let arry = []
					this.pictrueList.map(item => {
						arry.push(item)
						let dd = {
							url: item
						}
						this.fileList1.push(dd);
					})
					this.saveParams.pictures = arry.toString()
				}
			},
			deletePicture(e) {
				this.fileList1 = [];
				this.saveParams.pictures = "";
				if (e.length > 0) {
					let arry = []
					e.map(item => {
						arry.push(item)
						let dd = {
							url: item
						}
						this.fileList1.push(dd);
					})
					this.saveParams.pictures = arry.toString()
				}
			},
			saveConfirm() {
				const that = this
				if (this.btnType === 'add') {
					this.isInspec = 0
					this.infoShow = true
					this.btnType = 'save'
					this.htIndex = ''
					this.dataForm = {
						dangerLevel: '', //隐患等级 1.一般隐患；2.重大隐患；
						dangerPhoto: '', //照片
						dangerSite: this.regionName, //隐患位置
						dangerDesc: '', //隐患描述
						suggestion: this.suggestion, //整改意见
						rectifyDeptId: '',
						rectifyDeptName: '',
						realRectify: '',
						rectifyUid: "",
						rectifyName: "", //整改人姓名
						dangerReason: '',
						limitDate: '', //整改时限
						remark: '',
						deptIds: '', //公示部门
						publicityFlag: false, // 隐患是否公示；0.否；1.是;
						publicityDeptIds: '', //公式部门id
						publicityDeptNames: '', //公式部门名称
						sendSmsFlag: false, //是否发送短信；0.否；1.是；
						danger_type: 1, //1.企业自查隐患; 2.风险管控隐患
					}
					this.file = []
					if (this.isRiks) {
						this.dataForm.dangerSite = this.unitName 
					}
					this.fileList1 = [];
					this.saveParams.pictures = ''

				} else {
					console.log('isRiks',this.isRiks)
					const params = {
						ruleId: this.ruleId,
						inspectionId: this.inspectionId,
						dangerFlag: 1,
						dangerPhoto: this.saveParams.pictures,
						dangerType: this.isRiks ? 2 : 1, // 1.企业自查隐患; 2.风险管控隐患
					}
					if (this.dataForm.dangerLevel == '') {
						uni.$u.toast('请选择隐患等级')
						return
					}
					if (this.dataForm.dangerSite == '') {
						uni.$u.toast('请填写隐患位置')
						return
					}
					if (this.saveParams.pictures == '') {
						uni.$u.toast('请添加隐患照片')
						return
					}
					if (this.dataForm.dangerDesc == '') {
						uni.$u.toast('请填写隐患描述')
						return
					}

					if (this.dataForm.rectifyUid == '') {
						uni.$u.toast('请选择整改人')
						return
					}
					if (this.dataForm.limitDate == '') {
						uni.$u.toast('请选择整改时限')
						return
					}
					if (this.dataForm.publicityFlag && this.dataForm.publicityDeptIds == '') {
						uni.$u.toast('请选择公示部门')
						return
					}
					// 编辑
					if (this.dataForm.id) {
						params.id = this.dataForm.id
					}
					// 有隐患
					params.dangerLevel = this.dataForm.dangerLevel
					params.dangerSite = this.dataForm.dangerSite //隐患位置
					params.dangerDesc = this.dataForm.dangerDesc //隐患描述
					params.suggestion = this.dataForm.suggestion //整改意见
					params.rectifyDeptId = this.dataForm.rectifyDeptId
					params.rectifyDeptName = this.dataForm.rectifyDeptName
					params.rectifyUid = this.dataForm.rectifyUid
					params.rectifyName = this.dataForm.rectifyName //整改人姓名
					params.dangerReason = this.dataForm.dangerReason //隐患形成原因
					params.limitDate = this.dataForm.limitDate //整改时限
					params.publicityFlag = this.dataForm.publicityFlag ? 1 : 0 //短信通知
					params.publicityDeptIds = this.dataForm.publicityDeptIds //公示部门id
					params.publicityDeptNames = this.dataForm.publicityDeptNames //公示部门name
					params.sendSmsFlag = this.dataForm.sendSmsFlag ? 1 : 0 //短信通知
					params.danger_type = this.dataForm.danger_type


					uni.$u.http.post(`/check/mobile/appDangerInfo/addDangerInfo`, params).then(res => {
						if (res.code == 0) {
							uni.$u.toast('保存成功');
							that.infoShow = false
							this.btnType = 'add'
							//无论怎么样保存完成之后我都调用一下列表并清空数据
							this.getHtList()

						}
					})
				}
			},
			//点击删除按钮事件
			delItem: function(item, e) {
				let that = this;
				// that.htLists.splice(e.data.index, 1);
				uni.showModal({
					title: '提示',
					// 提示文字
					content: '请确认是否删除该条隐患？',
					// 取消按钮的文字自定义
					cancelText: "取消",
					// 确认按钮的文字自定义
					confirmText: "删除",
					confirmColor: '#f54e40',
					//取消字体的颜色
					cancelColor: '#000000',
					success: function(res) {
						if (res.confirm) {
							uni.$u.http.delete(
								`/expert/app/danger/appDangerInfo/deleteDangerInfo/${item.id}`).then(
								res => {
									if (res.code == 0) {
										uni.$u.toast('删除成功!');
										that.getHtList()
										that.htIndex = ''
									}
								}
							)
						} else {
							// 执行取消后的操作
						}
					}
				})
			},
			//详情接口以及渲染数据
			getHtDetail(item, config) {
				this.file = []
				uni.$u.http.get(`/check/mobile/appDangerInfo/getDangerDetail/${item.id}`).then(
					res => {
						if (res.code === 0) {
							this.infoShow = config
							this.dataForm = res.data
							this.dataForm.rule = res.data.rule || '无'
							this.dataForm.sendSmsFlag = res.data.sendSmsFlag ? true : false
							this.dataForm.publicityFlag = res.data.publicityFlag ? true : false
							this.dataForm.realRectify = res.data.rectifyDeptName + '-' + res.data.rectifyName
							this.handleFileList(res.data)
							//异常照片
							this.fileList1 = [];
							this.saveParams.pictures = res.data.dangerPhoto;

							// 图片回显
							this.file = res.data.dangerPhoto
							if (res.data.dangerPhoto != '') {
								// 图片回显
								let arr = []
								res.data.dangerPhoto.split(',').map(item => {
									let dd = {
										url: item
									}
									arr.push(dd);
								})
								this.fileList1 = arr
							} else {
								this.fileList1 = []
							}
							this.htInfo = JSON.parse(JSON.stringify(this.dataForm))
						}
					}
				)
			},
			//处理判断是图片还是video
			handleFileList(data) {
				let dangerPhoto = data.dangerPhoto
				if (dangerPhoto) {
					let fileList = dangerPhoto.split(",")

					fileList.forEach(item => {
						let str = item.split('?')[0]
						if (str.substring(str.length - 3, str.length) == 'mp4') {
							this.videoList.push(item)
							console.log(this.videoList)
						} else {
							console.log(this.imgList)
							this.imgList.push(item)
						}
					})
				}
			},
			//预览图片
			previewImage: function(e, s) {
				let imgList = []
				if (s.pictures) {
					imgList = this.getpictureList(s.pictures)
				} else {
					imgList = s
				}
				uni.previewImage({
					current: e,
					urls: imgList,
				});
			},
			//处理图片
			getpictureList(pictureinfo) {
				if (pictureinfo) {
					var splitAdd = pictureinfo.split(",");
					var imgList = []
					for (let i = 0; i < splitAdd.length; i++) {
						let iOrV = splitAdd[i].split("?")[0].split(".")
						let iOrVL = splitAdd[i].split("?")[0].split(".").length - 1
						if (iOrV[iOrVL] != 'mp4') {
							imgList.push(splitAdd[i])
						}
					}
					return imgList
				} else {
					return []
				}
			},
			//获取详情
			handleHtDetail(item, index) {
				//  && index !== this.htIndex
				if (this.btnType != 'add') {
					let that = this;
					uni.showModal({
						title: '提示',
						content: '当前信息未保存是否继续查看详情？',
						confirmText: '确定',
						cancelText: '取消',
						success: (res) => {
							if (res.confirm) {
								let config = true
								this.btnType = 'add'
								if (index === this.htIndex) {
									config = !this.infoShow
									this.htIndex = ''
								} else {
									config = true
									this.htIndex = index
								}
								if (config) {
									this.isInspec = 1
									this.imgList = []
									this.videoList = []
									this.getHtDetail(item, config)
								} else {
									this.infoShow = false
									this.isInspec = 0
									this.imgList = []
									this.videoList = []
								}
							} else {

							}
						},
					});
				} else {
					const that = this
					let config = true
					this.btnType = 'add'
					if (index === this.htIndex) {
						config = !this.infoShow
						this.htIndex = ''
					} else {
						config = true
						this.htIndex = index
					}
					if (config) {
						this.isInspec = 1
						this.imgList = []
						this.videoList = []
						this.getHtDetail(item, config)
					} else {
						this.infoShow = false
						this.isInspec = 0
						this.imgList = []
						this.videoList = []
					}
				}
			},
			//这里写个方法便于判断当前列表信息是否未保存
			judge: function() {
				let obj = this.dataForm
				let type = false
				//1.先判断是否有id
				if (obj.id && this.infoShow) {
					//判断是否与之前的值一致不一致提示保存
					let oldObj = this.htInfo
					obj.dangerPhoto = this.saveParams.pictures
					//判断两个obj是否相同
					for (let key in obj) {
						if (obj[key] != oldObj[key]) {
							type = true
						}
					}
				} else {
					if (this.infoShow) {
						for (let key in obj) {
							if (obj[key]) {
								type = true
							}
						}
					}
				}
				return type
			},
			//返回按钮
			handleBack: async function() {
				const that = this
				const type = await this.judge()
				//这里要判断几个逻辑 1.添加未保存（提示） 2.查看已修改（提示） 3.查看未修改（不提示直接返回）
				if (type) {
					uni.showModal({
						title: '提示',
						// 提示文字
						content: '当前隐患信息未保存，确定返回？',
						// 取消按钮的文字自定义
						cancelText: "取消",
						// 确认按钮的文字自定义
						confirmText: "确定",
						//取消字体的颜色
						cancelColor: '#000000',
						success: function(res) {
							if (res.confirm) {
								// var pages = getCurrentPages(); //当前页面栈
								// if (pages.length > 1) {
								// 	var beforePage = pages[pages.length - 2]; //获取上一个页面实例对象
								// 	beforePage.$vm.dataForm.forEach(it => {
								// 		it.children.forEach(item => {
								// 			if (item.id == this.ruleId) {
								// 				item.dangerNum = that.htLists.length
								// 			}
								// 		})
								// 	})
								// 	beforePage.data.refreshIfNeeded = true;
								// }
								if (that.type == 0) {
									uni.navigateBack({
										delta: 1
									})
								} else {
									// uni.navigateTo({
									// 	url: `/pages/subPackagesA/troble/notTroble?inspectionId=${this.inspectionId}&planName=${this.planName}&isInspec=${0}`
									// })
									uni.navigateBack({
										delta: 2
									})
								}

							} else {
								// 执行取消后的操作
							}
						}
					})
				} else {
					// var pages = getCurrentPages(); //当前页面栈
					// if (pages.length > 1) {
					// 	var beforePage = pages[pages.length - 2]; //获取上一个页面实例对象
					// 	beforePage.$vm.dataForm.forEach(it => {
					// 		it.children.forEach(item => {
					// 			if (item.id == this.ruleId) {
					// 				item.dangerNum = that.htLists.length
					// 			}
					// 		})
					// 	})
					// 	beforePage.data.refreshIfNeeded = true;
					// }
					//返回上一页面
					if (this.type == 0) {
						uni.navigateBack({
							delta: 1
						})
					} else {
						// uni.navigateTo({
						// 	url: `/pages/subPackagesA/troble/notTroble?inspectionId=${this.inspectionId}&planName=${this.planName}&isInspec=${0}`
						// })
						uni.navigateBack({
							delta: 2
						})
					}

				}
			},
			onChangeGongshi(e) {
				this.dataForm.gongshi = e
			},
			onChangesendSmsFlag(e) {
				this.dataForm.sendSmsFlag = e
			},
			cancelTime(e) {
				this.showTime = false;
			},
			confirmTime(e) {
				this.showTime = false;
				const timeFormat = uni.$u.timeFormat;
				let timeValue = timeFormat(e.value, 'yyyy-mm-dd');
				this.dataForm.limitDate = timeValue;
			},
			handleBumen() {
				if (this.isInspec == 0) {
					this.showBumen = true
				}
			},
			handleTime() {
				if (this.isInspec == 0) {
					this.showTime = true
				}
			},
			handleUser() {
				uni.navigateTo({
					url: `/pages/subPackagesA/riskIdtion/userTree`
				})
			},
			handlePublicity() {
				if (this.isInspec == 0) {
					uni.navigateTo({
						url: `/pages/subPackagesA/troble/bumenSelect?selectIds=${this.dataForm.publicityDeptIds}`
					})
				}

			},
			onChangeReason(e) {
				this.dataForm.dangerReason = e.value[0].id
				this.showReason = false
			},
			cancelReason() {
				this.showReason = false
			},
		}
	}
</script>

<style lang="scss" scoped>
	.my-input {
		border-bottom: 1px solid #F5F5F5;

		/deep/ .u-input {
			background-color: #f2f2f2 !important;
		}

		.myLength {
			color: #909193;
			font-size: 12px;
			padding: 1px 4px;
		}
	}

	.weibao-item {
		display: flex;
		flex-direction: column;
		padding: 30rpx;
		border-bottom: 1px solid #f2f2f2;



		.item-top {
			width: 100%;
			display: flex;
			justify-content: space-between;
			align-items: center;
			color: #2b2b2b;

			.left {
				width: 100%;
				display: flex;
				min-height: 40rpx;
				word-break: break-all;
				word-wrap: break-word;
			}

			.right {
				color: #0F53AC;
			}

			.right2 {
				color: #fa4016;
			}
		}

		.item-bottom {
			font-size: 24rpx;
			color: #8c8c8c;
			margin-top: 10rpx;
		}
	}



	.htLists-box {
		// padding: 2px;
		// border: 1px solid #f5f5f5;
		// box-shadow: 0px 2px 0px 0px #f2f2f2;

		.htLists-tips {
			padding: 28rpx 32rpx;
			font-size: 14px;
			font-weight: 400;
			color: #8C8C8C;
			background: #F5F5F5;
		}


		.htLists-detail {
			border-bottom: 1px solid #f5f5f5;

			.htlist-detail-box {
				padding: 32rpx;
				display: flex;
				justify-content: space-between;

				.htlist-detail-left {
					width: 85%;

					.htLists-title {
						color: #2B2B2B;
						font-size: 16px;
						font-weight: 500;
						width: 100%;
						display: block;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}

					.htLists-name {
						color: #8C8C8C;
						font-size: 14px;
						font-weight: 400;
						width: 100%;
						margin-top: 10rpx;
						display: block;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}
				}


				.look-box {
					// width: 15%;
					display: flex;
					flex-direction: column;
					justify-content: end;
					align-items: center;

					image {
						width: 30px;
						height: 30px;
						color: rgba(179, 179, 179, 1);
					}

					.look {
						font-size: 12px;
						color: rgba(179, 179, 179, 1);
					}
				}

				.lox-box-true {
					// width: 15%;
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					overflow: hidden;

					image {
						width: 30px;
						height: 30px;
						filter: drop-shadow(rgba(15, 83, 172, 1) 0px 0);
					}

					.look {
						font-size: 12px;
						color: rgba(15, 83, 172, 1);
					}
				}
			}

		}
	}

	.sex-select {
		.sex-item {
			word-break: break-all;
			word-wrap: break-word;
			display: flex;
			justify-content: center;
			align-items: center;
			padding: 20rpx;
			border-bottom: 1px solid #f2f2f2;
		}
	}

	.image-box {
		display: flex;

		.image {
			width: 170rpx;
			height: 170rpx;
			margin-right: 10rpx;
		}
	}

	.popup {
		height: fit-content;
		width: 100%;
		background: #fff;

		picker-view {
			width: 100%;
			height: 500rpx;
			display: relative;
		}

		.picker-btn {
			display: flex;
			height: 100upx;
			width: 100%;
			line-height: 100upx;
			background: #fff;
			font-size: 34upx;
			z-index: 1;
			border-bottom: 1rpx solid #f8f8f8;

			.left {
				flex: 1;
				color: #0076FF;
				padding-left: 40upx;
				box-sizing: border-box;
			}

			.right {
				flex: 1;
				text-align: right;
				padding-right: 40upx;
				color: #FE4533;
				box-sizing: border-box;
			}
		}

		.picker-item {
			line-height: 100rpx;
			text-align: center;
		}
	}

	.imgBox {
		display: flex;

		.img {
			width: 27vw;
			height: 27vw;
			margin-bottom: 4vw;
			margin-right: 4vw;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.video {
			width: 27vw;
			height: 27vw;
			margin-bottom: 4vw;
			margin-right: 4vw;
		}
	}

	.sel {
		color: #8C8C8C;
	}

	.tip_box {
		width: 560rpx;
		padding-top: 64rpx;
		background-color: #fff;
		border-radius: 12rpx;
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);

		.title1 {
			text-align: center;
			margin-bottom: 32rpx;
			font-size: 32rpx;
			font-weight: 500;
		}

		.top {
			font-size: 16px;
			font-weight: 400;
			padding-bottom: 64rpx;
			color: #4D4D4D;
			text-align: center;
			border-bottom: 2rpx solid #e5e5e5;
		}

		.btn {
			display: flex;
			justify-content: center;
			align-items: center;

			.cacel_btn {
				text-align: center;
				font-size: 34rpx;
				font-weight: 500;
				color: #0F53AC;
				width: 50%;
				height: 112rpx;
				line-height: 112rpx;
			}

		}
	}
</style>
